using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;

namespace BpNTClassInternal
{
    [Serializable()]
    public class TypedList<T> : BindingList<T>, ITypedList
    {

        [NonSerialized()]
        private PropertyDescriptorCollection _Properties;

        internal TypedList(FieldInfo[] descriptorInfos)
        {
            List<BpNTPropertyDescriptor> Descripts = new List<BpNTPropertyDescriptor>();
            int Index = 0;
            foreach (FieldInfo Fi in descriptorInfos)
            {
                Descripts.Add(new BpNTPropertyDescriptor(Index++, Fi.Caption, Fi.FieldTypeDotNet));
            }
            _Properties = new PropertyDescriptorCollection(Descripts.ToArray());
            // Alle Properties von dem Object T holen, ausser denen die Browsable(false) Attribute haben
            //_Properties = TypeDescriptor.GetProperties(typeof(T), new Attribute[] { new BrowsableAttribute(true) });

            //_Properties = new PropertyDescriptorCollection(new PropertyDescriptor[] { new MyPropDescr() });
            //_Properties.Add(new MyPropDescr());
        }

        #region ITypedList Implementation

        public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            return listAccessors == null ? _Properties : ListBindingHelper.GetListItemProperties(listAccessors[0].PropertyType);
        }
        public string GetListName(PropertyDescriptor[] listAccessors)
        {
            return typeof(T).Name;
        }
    }
        #endregion
}